package com.hmdp;

import java.lang.ref.WeakReference;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class y {
    public static void main(String[] args) {
        // 创建一个对象obj2
        String obj2 = new String("Weak Reference Example");

        // 创建一个弱引用指向obj2
        WeakReference<String> weakRef = new WeakReference<>(obj2);

        // 将obj2置为null
             obj2 = null;

        // 在适当的时机，垃圾回收机制可能会回收obj2
        System.out.println(weakRef.get());

        // 创建一个对象obj1
        String obj1 = new String("Strong Reference Example");

        // 创建一个强引用指向obj1
        String strongRef = obj1;

        // 将obj1置为null
        obj1 = null;

        // 此时仍然可以通过strongRef访问到对象
        System.out.println(strongRef);

        LocalDateTime now = LocalDateTime.now();
        String time = now.format(DateTimeFormatter.ofPattern("yyyy:MM:dd"));
        System.out.println(time);
    }

    }

